package bancosys.tec.persist.entities.domain;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;

import jmine.tec.persist.annotation.Alias;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

import bancosys.tec.persist.bussobj.PersistableBusinessObject;

@Entity
@Alias("CWCRED")
public class CWCred extends PersistableBusinessObject {

    private Long id;

    private List<CWEntry> entries = new ArrayList<CWEntry>();

    public void add(Long entity) {
        CWEntry entry = new CWEntry();
        entry.setCred(this);
        entry.setEntityId(entity);
        this.entries.add(entry);
    }

    @Id
    @GeneratedValue
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @OneToMany(mappedBy = "cred", targetEntity = CWEntry.class)
    @Cascade({ CascadeType.ALL, CascadeType.DELETE_ORPHAN })
    public List<CWEntry> getEntries() {
        return entries;
    }

    public void setEntries(List<CWEntry> entries) {
        this.entries = entries;
    }

}
